package com.example.baselibrary.utlis;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.CornerPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PathEffect;
import android.graphics.RectF;
import android.view.View;

public class FaceBoxView extends View {
    private Paint paint;
    private RectF faceBounds;
    private Matrix transformationMatrix;

    public FaceBoxView(Context context) {
        super(context);
        paint = new Paint();
        paint.setColor(Color.GREEN);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(4.0f);
        paint.setAntiAlias(true);
        transformationMatrix = new Matrix();
    }

    public void setTransformationMatrix(Matrix matrix) {
        this.transformationMatrix = new Matrix(matrix);
    }

    public void setFaceBounds(RectF rect) {
        this.faceBounds = rect;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (faceBounds != null) {
            PathEffect cornerPathEffect = new CornerPathEffect(16f); // 圆角效果
            paint.setPathEffect(cornerPathEffect);
            canvas.drawRect(faceBounds, paint);
        }
    }
}